********************************************************************************
**  TITLE:      il2003_ines_contact_networks                                  **  
**  AUTHOR:	    Philippe Mongrain                                             **
**  DATA:       2003                                                          **
**	DATE:		October 2022 					                              **	
**  VERSION:	Stata 16					                                  **	
********************************************************************************

* Version control

version 16.0

* Open log file

capture log close       			  			              
log using "il2003_ines_contact_networks", replace

* Open the dataset

use "2003.dta", clear 


***************************
** INDEPENDENT VARIABLES **
***************************

* Time

gen sdate = .

replace sdate = 20030112 if b96 == 12
replace sdate = 20030113 if b96 == 13
replace sdate = 20030114 if b96 == 14
replace sdate = 20030115 if b96 == 15
replace sdate = 20030117 if b96 == 17
replace sdate = 20030119 if b96 == 19
replace sdate = 20030120 if b96 == 20
replace sdate = 20030121 if b96 == 21
replace sdate = 20030124 if b96 == 24

gen surveydate=date(string(sdate,"%8.0f"),"YMD")

format %tdMon_DD,_CCYY surveydate

gen edate = 20030128

gen electiondate=date(string(edate,"%8.0f"),"YMD")

format %tdMon_DD,_CCYY electiondate

gen time = electiondate - surveydate

* Gender

gen male = b92

recode male (2=0)

* Age

gen age = b74

replace age = . if age < 17

* Education

gen education = b82

* Coalition preference

gen coalprefA = b59
gen coalprefB = b60
gen coalprefC = b61
gen coalprefD = b62

gen coalpref_complete = 1 if coalprefA!=. & coalprefB!=. & coalprefC!=. & coalprefD!=.

gen coalpref = 3 if coalprefA >= coalprefB & coalprefA >= coalprefC & coalprefA >= coalprefD & coalpref_complete == 1
replace coalpref = 2 if coalprefA == coalprefB & coalprefA == coalprefC & coalprefA == coalprefD & coalpref_complete == 1
replace coalpref = 1 if coalpref!=2 & coalpref!=3 & coalpref_complete == 1

replace coalpref = . if coalpref == 3 & coalprefA == coalprefB & coalpref_complete == 1
replace coalpref = . if coalpref == 3 & coalprefA == coalprefC & coalpref_complete == 1
replace coalpref = . if coalpref == 3 & coalprefA == coalprefD & coalpref_complete == 1

label define coalpref 1 "Loser coalition" 2 "No coalpref" 3 "Winner coalition"
label values coalpref coalpref

* Coalition preference strength

gen coalstrengthA = coalprefA if coalprefA >= coalprefB & coalprefA >= coalprefC & coalprefA >= coalprefD & coalpref_complete == 1
gen coalstrengthB = coalprefB if coalprefB >= coalprefA & coalprefB >= coalprefC & coalprefB >= coalprefD & coalpref_complete == 1
gen coalstrengthC = coalprefC if coalprefC >= coalprefA & coalprefC >= coalprefB & coalprefC >= coalprefD & coalpref_complete == 1
gen coalstrengthD = coalprefD if coalprefD >= coalprefA & coalprefD >= coalprefB & coalprefD >= coalprefC & coalpref_complete == 1

gen coalstrength = max(coalstrengthA,coalstrengthB,coalstrengthC,coalstrengthD)

replace coalstrength = 300 if coalstrength == 4 | coalstrength == 5
replace coalstrength = 200 if coalstrength == 3
replace coalstrength = 100 if coalstrength == 1 | coalstrength == 2

replace coalstrength = 3 if coalstrength == 300
replace coalstrength = 2 if coalstrength == 200
replace coalstrength = 1 if coalstrength == 100

label define coalstrength 1 "Weak coalpref" 2 "Moderate coalpref" 3 "Strong coalpref"
label values coalstrength coalstrength

* Coalition coalpref scale

gen coalscale = .

replace coalscale = 1 if coalpref == 1 & coalstrength == 3
replace coalscale = 2 if coalpref == 1 & coalstrength == 2
replace coalscale = 3 if coalpref == 1 & coalstrength == 1
replace coalscale = 4 if coalpref == 2
replace coalscale = 5 if coalpref == 3 & coalstrength == 1
replace coalscale = 6 if coalpref == 3 & coalstrength == 2
replace coalscale = 7 if coalpref == 3 & coalstrength == 3

label define coalscale 1 "Strong loser coalpref" 2 "Moderate loser coalpref" 3 "Weak loser coalpref" 4 "No coalpref" 5 "Weak winner coalpref" 6 "Moderate winner coalpref" 7 "Strong winner coalpref" 
label values coalscale coalscale

* Political discussion

gen discussion = 4 - a74

gen discussion_3pts = discussion
replace discussion_3pts = 0 if discussion == 1
replace discussion_3pts = 1 if discussion == 2
replace discussion_3pts = 2 if discussion == 3


*********************************
** NATIONAL-LEVEL EXPECTATIONS ** 
*********************************

* Generate variable identifying incomplete answers

gen winCoalitionA = b47
gen winCoalitionB = b50
gen winCoalitionC = b53
gen winCoalitionD = b56

gen complete_whole = 1 if winCoalitionA!=. & winCoalitionB!=. & winCoalitionC!=. & winCoalitionD!=.

* Generate value of 1 if the expectation for one coalition is higher or equal to the expectations for at least one other coalition

gen coalitionA = 1 if winCoalitionA >= winCoalitionB & winCoalitionA >= winCoalitionC & winCoalitionA >= winCoalitionD & complete_whole == 1

gen coalitionB = 1 if winCoalitionB >= winCoalitionA & winCoalitionB >= winCoalitionC & winCoalitionB >= winCoalitionD & complete_whole == 1

gen coalitionC = 1 if winCoalitionC >= winCoalitionA & winCoalitionC >= winCoalitionB & winCoalitionC >= winCoalitionD & complete_whole == 1

gen coalitionD = 1 if winCoalitionD >= winCoalitionA & winCoalitionD >= winCoalitionB & winCoalitionD >= winCoalitionC & complete_whole == 1

gen coalitionOTH = 1 if winCoalitionA == 0 & winCoalitionB == 0 & winCoalitionC == 0 & winCoalitionD == 0 & complete_whole == 1

replace coalitionA = . if coalitionOTH == 1 & complete_whole == 1
replace coalitionB = . if coalitionOTH == 1 & complete_whole == 1
replace coalitionC = . if coalitionOTH == 1 & complete_whole == 1
replace coalitionD = . if coalitionOTH == 1 & complete_whole == 1

* Generate variable for ambiguous forecasts

gen ambiguous_whole = .

replace ambiguous_whole = 99 if coalitionA == coalitionB & coalitionA!=. | coalitionA == coalitionC & coalitionA!=. | coalitionA == coalitionD & coalitionA!=. 

replace ambiguous_whole = 99 if coalitionB == coalitionA & coalitionB!=. | coalitionB == coalitionC & coalitionB!=. | coalitionB == coalitionD & coalitionB!=.

replace ambiguous_whole = 99 if coalitionC == coalitionA & coalitionC!=. | coalitionC == coalitionB & coalitionC!=. | coalitionC == coalitionD & coalitionC!=.

replace ambiguous_whole = 99 if coalitionD == coalitionA & coalitionD!=. | coalitionD == coalitionB & coalitionD!=. | coalitionD == coalitionC & coalitionD!=.

* Generate value of 0 for lower expectations

replace coalitionA = 0 if coalitionA!=1 & coalitionA!=. & complete_whole == 1
replace coalitionB = 0 if coalitionB!=1 & coalitionB!=. & complete_whole == 1
replace coalitionC = 0 if coalitionC!=1 & coalitionC!=. & complete_whole == 1
replace coalitionD = 0 if coalitionD!=1 & coalitionD!=. & complete_whole == 1
replace coalitionOTH = 0 if coalitionOTH!=1 & coalitionOTH!=. & complete_whole == 1

* Forecasts (1 = Likud-right-religious coalition, 2 = Likud-Labor-Shinui coalition, 3 = Labor-Meretz-Arabs coalition, 4 = national unity government, 88 = other, 99 = ambiguous)

gen forecast_whole = .

replace forecast_whole = 1 if coalitionA == 1 & complete_whole == 1
replace forecast_whole = 2 if coalitionB == 1 & complete_whole == 1
replace forecast_whole = 3 if coalitionC == 1 & complete_whole == 1
replace forecast_whole = 4 if coalitionD == 1 & complete_whole == 1
replace forecast_whole = 88 if coalitionOTH == 1 & complete_whole == 1
replace forecast_whole = 99 if ambiguous_whole == 1 & complete_whole == 1

* Identify correct and ambiguous forecasts

gen correct_whole = 0 if forecast_whole!=1 & forecast_whole!=. & complete_whole == 1
replace correct_whole = 1 if forecast_whole == 1 & complete_whole == 1

replace correct_whole = 99 if forecast_whole == 99 & coalitionA == 1 & complete_whole == 1

* Generate dichotomous variable (treat ambiguous forecasts as incorrect)

gen correct_whole_d = correct_whole

replace correct_whole_d = 0 if correct_whole_d == 99
replace correct_whole_d = 1 if correct_whole_d == 1


**********
** SAVE **
**********

save "il2003_ines.dta", replace


*******************
** MAIN ANALYSES **
*******************

* Regression analysis and percentage of correct and incorrect forecasts

logistic correct_whole_d discussion coalscale age i.male education time
estimates table, star(.05 .01 .001)

tab correct_whole_d if e(sample) == 1


************************
** SUMMARY STATISTICS **
************************

label variable correct_whole_d "Coalition formed (DV)"
label variable discussion "Discussion"
label variable coalscale "Coalition preference"
label variable age "Age"
label variable male "Gender (male = 1)"
label variable education "Education"
label variable time "Time of interview"

estpost tabstat correct_whole_d discussion coalscale age male education time if e(sample) == 1, statistics(n mean p50 sd min max) columns(statistics)

esttab using "il2003_ines_summary_national.tex", substitute("\begin{table}[htbp]" "\begin{table}[H]") cells("count(label(N) fmt(%9.0fc)) mean(fmt(%5.2f) label(Mean)) p50(fmt(%5.1f) label(Median)) sd(fmt(%5.1f) label(Std. dev.)) min(fmt(%5.1f) label(Min)) max(fmt(%5.1f) label(Max))") label width(\textwidth) nomtitle nonumber noobs booktabs title("Summary statistics -- 2003 Israeli legislative election (INES), national level") replace

eststo clear

log close